home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
tegl6b.zip
/
INTROPAK.EXE
/
lha
/
TWDEMO.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-08-14
|
17KB
|
497 lines
{$I switches.inc}
{-------------------------------------------------------------------}
{ TWDEMO.PAS }
{ Copyright 1991 TEGL SYSTEMS CORPORATION, All rights reserved. }
{-------------------------------------------------------------------}
{$F+} {-- far call is necessary for EVENTS }
Uses
teglfont, {-- the graphics group }
fastgrph,
tgraph,
virtmem, {-- memory }
teglintr,
teglunit, {-- window manager, menus and micellaneous }
teglmenu,
teglmain,
teglspec,
twcommon, {-- high-level windows }
twkernel,
twwindow,
twworld,
twdialog,
twcontrl;
{-- Global variables }
VAR
TechnaFont : Integer;
TallFont : Integer;
mainmenu: ImageStkPtr; {-- the main bar menu is only an ordinary frame}
{-- with option menu click areas placed on it. }
menufont: pointer; {-- the font to use with all menus. Set once so }
{-- we can make the program look better on }
{-- a variety of video displays. }
fileom : optionmptr;
devicesom: optionmptr;
dialogom : optionmptr;
worldom : optionmptr;
{-- restores all the frames to being active and close the error }
{-- message window. }
function errorclose(ifs: imagestkptr; ms: msclickptr): Word;
BEGIN
resetframeactive(stackptr,true);
twclose(findwinframe(ifs));
END;
{-- Display an error message and disable all other frames until }
{-- the OK button is pressed. }
procedure SayError(s: String);
VAR wf : WinFramePtr;
BEGIN
{ resetframeactive sets the activity of all the frames from }
{ the one passed (here the topmost) to the bottom of the stack.}
{ In this case all frames become inactive then we create one }
{ active frame (the error message) that must be delt with, before}
{ processing can continue. }
resetframeactive(stackptr,false); {-- disable everything }
twdInit(wf,0,(getmaxy DIV 2) - 35,getmaxx,(getmaxy DIV 2) + 35);
twsetHeader(wf,'ERROR'); {-- set the header }
twSetMaximize(wf,false); {-- disable MIN/MAX buttons }
{-- add a button that will acknowlege the error }
twdAddButton(wf,getmaxx DIV 2 - 20, 25, 'OK',errorclose);
twsetcloseevent(wf,errorclose); {-- space bar menu CLOSE }
twDrawWindowFrame(wf); {-- finally draw the window }
{-- display the message. }
prepareforupdate(wf^.ifs); {-- going to write to the window }
settextjustify(centertext,toptext);
OutTextXY((getmaxx DIV 2) - (wf^.thickness *2),5,s);
commitupdate; {-- finished writing to the window }
END;
{---------------------------------------------------------}
{-- These are some global variable for our dialog window to access }
CONST wf : WinFramePtr = NIL;
strtd: string[20] = 'This is a string';
chkbox : boolean = TRUE;
radio : integer = 2;
{-- Note that closing a dialog calls twdClose not twClose, it must}
{-- first dispose of the list of dialog entries before the window }
function dialogclose(ifs : ImageStkPtr; ms: MsClickPtr): Word;
begin
dialogclose := twdClose(ifs,ms);
wf := NIL;
end;
{-- Opens up a simple dialog window. }
Function OpenDialogDemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
VAR tempifs : imagestkptr;
BEGIN
if wf <> NIL then {-- only one allowed. }
begin
sayerror('The dialog demo is already running.');
exit;
end;
twdInit(wf,100,100,400,300);
twSetHeader(wf,'Simple Dialogue');
twdAddLabel(wf,10,10,'Labels go anywhere');
{-- input lines are string items, the last parameter is the }
{-- length of the string. }
twdAddInputLine(wf,10,30,'Edit this ',strtd,20);
{-- check boxes are boolean values }
twdAddCheckBox(wf,10,50,'a check box',chkbox);
{-- radio buttons all access the same integer value. Their }
{-- order is important. The first one will be one the }
{-- second two, etc. Groups of radio buttons must be seperated }
{-- by either some other dialog item or a label, if nothing is }
{-- required use an empty label. }
twdAddRadioButton(wf,10,70,'a radio button (1)',radio);
twdAddRadioButton(wf,10,90,'a radio button (2)',radio);
twdAddRadioButton(wf,10,110,'a radio button (3)',radio);
{-- Buttons are associated with events, here the OK button does }
{-- nothing, but the cancel button closes the dialog. }
twdAddbutton(wf,50,150,'OK',nilunitproc);
twdAddButton(wf,180,150,'CANCEL',dialogclose);
twSetCloseEvent(wf,dialogclose); {-- the space bar menu }
{-- Note that the window is only drawn AFTER ALL THE DIALOG ITEMS }
{-- HAVE BEEN SET. }
twDrawWindowFrame(wf);
END;
{-- The key to using scaled text is by setting the usercharsize }
{-- with the ratio of the working area to the screen size }
Function WorldTextRedraw(ifs: ImageStkPtr; ms: MsClickPtr): Word;
VAR wf: WinFramePtr;
BEGIN
wf := FindWinFrame(ifs);
twSelect(wf);
twwDefineWorld(wf,0,0,1000,1000);
PrepareforUpdate(ifs);
SetTextJustify(lefttext,toptext);
SetTextStyle(TechnaFont,horizdir,2);
SetUserCharSize(wf^.wx2-wf^.wx1,getmaxx DIV 2,
wf^.wy2-wf^.wy1,getmaxy DIV 2);
twwOutTextXY(wf,10,10,'Scaled text');
SetTextStyle(TallFont,Horizdir,5);
SetUserCharSize(wf^.wx2-wf^.wx1,getmaxx DIV 2,
wf^.wy2-wf^.wy1,getmaxy DIV 2);
twwOutTextXY(wf,10,500,'Using Triplex & Small Font');
CommitUpDate;
END;
Function OpenWorldTextDemo(ifs: ImageStkPtr; ms: MsClickPtr): Word;
VAR wf : WinFramePtr;
BEGIN
twinit(wf,100,100,300,250);
twSetHeader(wf,'Scaling text');
twSetRedraw(wf,WorldTextRedraw);
twDrawWindowFrame(wf);
END;
{---------------------------------------------------------}
{-- Bar graph demo illustrates how to use the world coordinates }
{-- to fit data into any sized window. }
{---------------------------------------------------------}
CONST MaxBars = 10;
TYPE BarDef = RECORD x1,y1,x2,y2,color: Integer; END;
CONST Bars : Array[1..MaxBars] OF BarDef =
(
(x1:-99;y1:80;x2:-81;y2:0;Color:blue),
(x1:-80;y1:70;x2:-61;y2:0;Color:blue),
(x1:-60;y1:20;x2:-41;y2:0;Color:blue),
(x1:-40;y1:0;x2:-21;y2:-40;Color:red),
(x1:-20;y1:0;x2:-1;y2:-99;Color:red),
(x1:1;y1:0;x2:20;y2:-67;Color:red),
(x1:21;y1:8;x2:40;y2:0;Color:green),
(x1:41;y1:20;x2:60;y2:0;Color:yellow),
(x1:61;y1:75;x2:80;y2:0;Color:magenta),
(x1:81;y1:50;x2:99;y2:0;Color:blue));
Function rtos(r: real) : string;
var s : String;
BEGIN
str(r:5:1,s);
rtos := s;
END;
Function WorldBarRedraw(ifs : ImageStkPtr; ms : MsClickPtr): Word;
VAR wf: WinFramePtr;
I : Integer;
BEGIN
wf := FindWinFrame(ifs);
twwDefineWorld(wf,-100,100,100,-100);
twwLine(wf,-100,0,100,0);
twSetFont(wf,@f6x6norm);
for I := 1 to MaxBars DO
WITH BARS[I] DO
BEGIN
SetFillStyle(solidfill,color);
twwBar(wf,x1,y1,x2,y2);
SetColor(Black);
twwRectangle(wf,x1,y1,x2,y2);
{twwOutTextXy(wf,x1,y1,'('+rtos(x1)+','+rtos(y1)+')'); }
END;
SetColor(BLACK);
{twwOutTextXy(wf,-10,-10,'(0,0)');}
END;
Function WorldSinRedraw(ifs : ImageStkPtr; ms : MsClickPtr): Word;
VAR wf: WinFramePtr;
t : real;
const
counter : real = 0.05;
range : real = 8.0;
BEGIN
wf := FindWinFrame(ifs);
twwDefineWorld(wf,-(range * 1.2),(range * 1.2),(range * 1.2),-(range * 1.2));
twwline(wf,-range,0,range,0);
twwline(wf,0,-range,0,range);
twwline(wf,-range,range,-range,-range);
twwline(wf,-range,-range,range,-range);
setcolor(red);
t := -range;
while t <= range do
begin
{ twwputpixel(wf,t,range * sin(t),red); }
twwline(wf,t,range * sin(t),t+counter,range * sin(t+counter));
t := t + counter;
end;
setcolor(black);
END;
Function OpenWorldBarDemo(